package com.barbeque.mall.service.wx;

import com.barbeque.mall.bean.advertise.MarketTopic;
import com.barbeque.mall.bean.advertise.MarketTopicExample;
import com.barbeque.mall.mapper.MarketTopicMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.barbeque.mall.bean.BasePageInfo;
import com.barbeque.mall.bean.advertise.MarketTopic;
import com.barbeque.mall.bean.goods.MarketGoods;
import com.barbeque.mall.bean.param.CommonData;
import com.barbeque.mall.bean.wx.topic.WxMarketTopic;
import com.barbeque.mall.bean.wx.topic.WxMarketTopicExample;
import com.barbeque.mall.bean.wx.topic.WxMarketTopicGoods;
import com.barbeque.mall.mapper.MarketGoodsMapper;
import com.barbeque.mall.mapper.MarketTopicMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 苏东宇
 * @since 2022/07/20 23:55
 */

/**
 * @author why
 * @since 2022/07/21 10:05
 */
@Service
public class WxTopicServiceImpl implements WxTopicService {
    @Autowired
    MarketTopicMapper marketTopicMapper;
    @Autowired
    MarketGoodsMapper marketGoodsMapper;


    @Override
    public List<MarketTopic> getTopicList() {
        MarketTopicExample marketTopicExample = new MarketTopicExample();
        MarketTopicExample.Criteria criteria = marketTopicExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        PageHelper.startPage(1, 4);
        List<MarketTopic> marketTopics = marketTopicMapper.selectByExample(marketTopicExample);

        return marketTopics;
    }

    @Override
    public CommonData<WxMarketTopic> selectTopicRelated() {
//        PageHelper.startPage(info.getPage(), info.getLimit());

        WxMarketTopicExample example = new WxMarketTopicExample();
        WxMarketTopicExample.Criteria criteria = example.createCriteria();
        //      example.setOrderByClause(info.getSort() + " " + info.getOrder());
        List<WxMarketTopic> wxMarketTopics = marketTopicMapper.selectWxByExampleLimit(example);
        PageInfo<WxMarketTopic> wxMarketTopicPageInfo = new PageInfo<>(wxMarketTopics);
        return CommonData.data(wxMarketTopicPageInfo);
    }

    @Override
    public CommonData<WxMarketTopic> selectTopicList(BasePageInfo info) {
        PageHelper.startPage(info.getPage(), info.getLimit());

        WxMarketTopicExample example = new WxMarketTopicExample();
        WxMarketTopicExample.Criteria criteria = example.createCriteria();
        example.setOrderByClause(info.getSort() + " " + info.getOrder());
        //criteria.andDeletedEqualTo(false);
        List<WxMarketTopic> wxMarketTopics = marketTopicMapper.selectWxByExample(example);
        PageInfo<WxMarketTopic> wxMarketTopicPageInfo = new PageInfo<>(wxMarketTopics);

        return CommonData.data(wxMarketTopicPageInfo);
    }

    @Override
    public WxMarketTopic selectTopicDetail(Integer id) {
        WxMarketTopic marketTopic = marketTopicMapper.selectWxByPrimaryKey(id);
        return marketTopic;
    }

    @Override
    public WxMarketTopicGoods selectTopicGoodsList(Integer ids) {
        WxMarketTopicGoods wxMarketTopicGoods = marketGoodsMapper.selectWxByPrimaryKey(ids);
        return wxMarketTopicGoods;
    }


}
